package leetcode;

import java.util.ArrayList;
import java.util.List;

public class ListNode {
	int val;
	public ListNode next;

	ListNode(int x, ListNode next) {
		val = x;
		this.next = next;
	}

	ListNode(int x) {
		val = x;
		next = null;
	}

	@Override
	public String toString() {
		return this.val + "->" + (null == next ? "null" : next.toString());
	}

	public static ListNode prepareListNode(int[] ints) {

		ListNode preNode = null;
		ListNode first = null;
		for (int i = 0; i < ints.length; i++) {
			int val = ints[i];
			ListNode ln = new ListNode(val);
			if (null != preNode) {
				preNode.next = ln;
			}
			preNode = ln;
			if (0 == i) {
				first = ln;
			}
		}
		return first;
	}
}
